﻿@using EasyCourse.Model;
@{
    CommonPageInfo pageInfo = ViewData[CommonViewDataKey.CommonPageInfo] as CommonPageInfo;
    string para = "?CourseId=" + pageInfo.CourseId;
}
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <title>讨论区管理</title>
    @Html.Partial("~/Views/Share/PublicHeader.cshtml")
</head>
<body>
    @Html.Partial("~/Views/Share/PublicTopNav4Teacher.cshtml")
    <div class="container">
        <div class="row">
            <h1 class="topTitle-h1">
                @pageInfo.CourseName<br>
                <small>广州中医药大学康复治疗微课程网络学习平台</small>
            </h1>
        </div>
    </div>
    @*导航菜单*@
    @Html.Partial("~/Views/Share/PublicTeacherNaviMenu.cshtml", 2)
    <div class="container mainwrap">
        <div class="row">
            <div class="col-xs-2">
                <div class="dropdown theme-dropdown clearfix">
                    <a id="dropdownMenu1" href="#" role="button" class="sr-only dropdown-toggle" data-toggle="dropdown">Dropdown <span class="caret"></span></a>
                    <ul class="dropdown-menu" role="menu" aria-labelledby="dropdownMenu1">
                        <li class="active" role="presentation">
                            <a role="menuitem" tabindex="-1" href="yue-courseIntro.html">
                                <span class="glyphicon glyphicon-bookmark"></span>讨论区管理
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
            <div class="col-xs-10">
                <div class="panel panel-default mainwrap-part">
                    <div class="panel-heading">
                        <h3 class="panel-title">
                            <ol class="breadcrumb">
                                <li>讨论区管理</li>
                                <li class="active">讨论区管理</li>
                            </ol>
                        </h3>
                    </div>
                    <div class="panel-body">
                        <div class="row">
                            <form class="form-horizontal" role="form">
                                <div class="form-group">
                                    <div class="col-xs-3">
                                        <input type="text" id="titleSearchTxt" class="form-control input-md" placeholder="请输入标题" />
                                    </div>
                                    <div class="col-xs-2">
                                        <select id="isTopSel" class="form-control input-md">
                                            <option value="">是否置顶</option>
                                            <option value=true>是</option>
                                            <option value=false>否</option>
                                        </select>
                                    </div>
                                    <div class="col-xs-2">
                                        <select id="isStopSel" class="form-control input-md">
                                            <option value="">是否停用</option>
                                            <option value=true>是</option>
                                            <option value=false>否</option>
                                        </select>
                                    </div>
                                    <div class="col-xs-5">
                                        <button type="button" onclick="getList(1)" class="btn btn-success btn-md"><span class="glyphicon glyphicon-search"></span>搜索 </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                        <div class="row">
                            <table class="table table-bordered tb1 table-striped table-hover">
                                <thead>
                                    <tr>
                                        <th width="30%">帖子内容标题</th>
                                        <th width="10%">创建时间</th>
                                        <th width="5%">是否停用</th>
                                        <th width="5%">是否置顶</th>
                                        <th width="5%">是否推荐</th>
                                        <th width="45%">操作</th>
                                    </tr>
                                </thead>
                                <tbody id="tbody"></tbody>
                            </table>
                        </div>
                        <div class="row clearfix well d-page">
                            <div id="PagInfo" class="pull-left sum">
                            </div>
                            <div class="clearfix pull-right">
                                <ul id="PageTool" class="pagination"></ul>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    @Html.Partial("~/Views/Share/PublicFooter.cshtml")
    @Html.Partial("~/Views/Share/PublicCommonJs.cshtml")
    <script>

            var tbody = $("#tbody");
            var _courseId = $.getUrlParam("CourseId");
            var options = false;
            var _state = false;
            function getList(pageNo) {

                $("#PagInfo").html("");
                $("#PageTool").html("");

                var _title = $("#titleSearchTxt").val();
                var _isStop = $("#isStopSel").val();
                var _isTop = $("#isTopSel").val();
                $.easyPost("@Url.Action("GetDiscussionInfoList", "DiscussionManage")", { "PageNO": pageNo, "PageSize": "10", "CourseId": _courseId, "Title": _title, "IsStop": _isStop, "IsTop": _isTop },
                   function (data) {
                       if (!data.result) {
                           showTips.open(data.message);
                           return;
                       }
                       var _html = '';
                       if (data.rows.length > 0) {
                           $(".d-page").show();

                           var _row = data.rows,
                               _rowL = _row.length;
                           options = {
                               totalPages: data.totalPage,
                               total: data.total,
                               currentPage: pageNo,
                               onPageClicked: function (event, originalEvent, type, page) {
                                   getList(page);
                               }
                           }
                           initialPaginator(options, "PageTool", "PagInfo");

                           for (var i = 0; i < _rowL; i++) {
                               var item = _row[i];
                               var _date = item.CreateTime.toString().replace(/\//g, "");
                               var time = eval('new ' + _date);
                               var isStop = item.IsStop;    //是否停用
                               var isTop = ((item.StatusCode & 2) == 2);     //是否置顶
                               var isRecommend = ((item.StatusCode & 1) == 1);   //是否推荐
                               _html += "<tr>";
                               _html += "<td>" + item.Title + "</td>";
                               _html += "<td>" + time.format('yyyy-MM-dd') + "</td>";
                               _html += "<td>" + (isStop ? "是" : "否") + "</td>";
                               _html += "<td>" + (isTop ? "是" : "否") + "</td>";
                               _html += "<td>" + (isRecommend ? "是" : "否") + "</td>";
                               _html += "<td>";
                               _html += "<a class='operate' href='javascript:void(0)'  onclick='statuesOn(\"" + item.Id + "\",\"" + "@StatusCodes.Up" + "\")'><span class='glyphicon glyphicon-arrow-up'></span>置顶</a>";
                               _html += "<a class='operate' href='javascript:void(0)'  onclick='statuesOff(\"" + item.Id + "\",\"" + "@StatusCodes.Up" + "\")'><span class='glyphicon glyphicon-arrow-down'></span>取消置顶</a>";
                               _html += "<a class='operate' href='javascript:void(0)'  onclick='statuesOn(\"" + item.Id + "\",\"" + "@StatusCodes.Recommend" + "\")'><span class='glyphicon glyphicon-hand-up'></span>推荐</a>";
                               _html += "<a class='operate' href='javascript:void(0)'  onclick='statuesOff(\"" + item.Id + "\",\"" + "@StatusCodes.Recommend" + "\")'><span class='glyphicon glyphicon-hand-down'></span>取消推荐</a>";
                               _html += "<a href='javascript:void(0)' onclick='switchChange(\"" + item.Id + "\")' class='operate'><span class='glyphicon glyphicon-stop'></span> " + (isStop ? "启用" : "停用") + "</a>";
                               _html += "<a target='_ablant' href='@Url.Action("Detail", "Discussion")@para&DiscussId="+item.Id+"' class='operate'><span class='glyphicon glyphicon-folder-open'></span>打开</a>";

                               _html += "</td>";
                               _html += "</tr>";
                           }
                       }
                       else {
                           _html = "<tr><td colspan='6' align='center'>暂无内容!</tr>";
                           $(".d-page").hide();
                       }
                       tbody.html(_html);
                   }, "json");
            }


            if (!!window.location.hash) {
                var _hash = window.location.hash.substr(1);
                getList(_hash);
            } else {
                getList(1);
            }


            //停用/启用讨论帖
            function switchChange(id) {
                $.easyPost("@Url.Action("DiscussionSwitchChange", "DiscussionManage")", { "Id": id },
                  function (data) {
                      if (!data.result) {
                          showTips.open(data.message);
                          return;
                      }
                      if (!!window.location.hash) {
                          var _hash = window.location.hash.substr(1);
                          getList(_hash);
                      } else {
                          getList(1);
                      }
                  }, "json");
            }

            //状态打开（置顶、推荐等状态的操作）
            function statuesOn(id, statusCode) {
                $.easyPost("@Url.Action("DiscussionStatuesOn", "DiscussionManage")", { "Id": id, "StatusCode": statusCode },
                  function (data) {
                      if (!data.result) {
                          showTips.open(data.message);
                          return;
                      }
                      if (!!window.location.hash) {
                          var _hash = window.location.hash.substr(1);
                          getList(_hash);
                      } else {
                          getList(1);
                      }
                  }, "json");
            }

            //状态关闭（取消置顶、取消推荐等状态的操作）
            function statuesOff(id, statusCode) {
                $.easyPost("@Url.Action("DiscussionStatuesOff", "DiscussionManage")", { "Id": id, "StatusCode": statusCode },
                 function (data) {
                     if (!data.result) {
                         showTips.open(data.message);
                         return;
                     }
                     if (!!window.location.hash) {
                         var _hash = window.location.hash.substr(1);
                         getList(_hash);
                     } else {
                         getList(1);
                     }
                 }, "json");
            }


            $(function () {
                $(window).scroll(function () {
                    if ($(window).scrollTop() >= 300) {
                        $('.actGotop').fadeIn(300);
                    } else {
                        $('.actGotop').fadeOut(300);
                    }
                });
                $('.actGotop').click(function () {
                    $('html,body').animate({ scrollTop: '0px' }, 800);
                });
            });
    </script>
</body>
</html>
